package com.skq.controller;

import com.skq.pojo.Article;
import com.skq.pojo.PageBean;
import com.skq.pojo.Result;
import com.skq.service.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author skq
 * @data 2024/6/6
 */
@RestController
@RequestMapping("/article")
@Tag(name = "文章相关接口")
@Validated
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @Operation(summary = "添加文章")
    @PostMapping
    public Result add(@RequestBody @Validated Article article) {
        articleService.add(article);

        return Result.success();
    }

    @Operation(summary = "分页查询文章")
    @GetMapping
    public Result<PageBean<Article>> list(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "3") Integer pageSize,
            @RequestParam(required = false) String categoryId,
            @RequestParam(required = false) String state
    ) {
        PageBean<Article> pb = articleService.list(pageNum, pageSize, categoryId, state);

        return Result.success(pb);

    }

}
